﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StarClub.Model;
using System.Web;

namespace StarClub.BLL
{
    /// <summary>
    /// 用户登录业务类
    /// </summary>
    public class LoginFacade
    {
        /// <summary>
        /// 用户登录的方法
        /// </summary>
        /// <param name="loginName"></param>
        /// <param name="passWord"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static bool Login(string loginName,string passWord,out string msg)
        {
            msg = string.Empty;
            if (string.IsNullOrEmpty(loginName) || string.IsNullOrEmpty(passWord))
            {
                msg = "请完整填写用户名和密码";
                return false;
            }
            StarClub.BLL.star_user BLL_User = new star_user();
            StarClub.Model.star_user Model_User=BLL_User.GetUser(loginName);
            if (Model_User == null)
            {
                msg = "用户名有误";
                return false;
            }
            if (Common.Md5.ToMd5(passWord) != Model_User.password)
            {
                msg = "密码有误";
                return false;
            }
            Model_User.password = "";
            HttpContext.Current.Session.Clear();
            HttpContext.Current.Session[SystemDefinition.SystemUser] = Model_User;
            return true;
        }
        /// <summary>
        /// 用户退出
        /// </summary>
        public static void Loginout()
        {
            HttpContext.Current.Session[SystemDefinition.SystemUser] = null;
            HttpContext.Current.Session.Clear();
        }
    }
}
